﻿using MessageHandlingServer.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MessageHandlingServer.Client
{
    public partial class MyOutput : Form
    {
        Server2.MyServer2 server2;
        Server1.MyServer1 server1;

        public MyOutput()
        {
            InitializeComponent();
            server2 = new Server2.MyServer2(s => textBox1.BeginInvoke(new Action<string>(DisplayText), new object[] { s })); ;
            server1 = new Server1.MyServer1(server2);
        }

        public void DisplayText(string text)
        {
            Random r = new Random();
            this.textBox1.AppendText(text);
            this.textBox1.BackColor = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
            this.Refresh();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                var m = new IntMessage(i+1);
                server1.ProcessMessage(m);
            }
        }
    }
}
